﻿#region Copyright (C) Sector7 Software Studio. All rights reserved
/*******************************************************************************************
 * Creation
 *      Author:         Mac
 *      Date:           2013/7/28 1:05:00
 *      Version:        
 * Modification 
 *      Author: 
 *      Date: 
 *      Description: 
 *      Version:
 *******************************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Sector7.Framework.DB;
using Sector7.Medical.EntityType;
using Sector7.Medical.Consts;
using Sector7.Medical.DAO.Utility;

namespace Sector7.Medical.DAO.Standard
{
    /// <summary>
    /// <!-- The description about this class. -->
    /// </summary>
    public class RegistryFeeDAO : DAOBase<M7_RegistryFee>,IRegistryFeeDAO
    {
        #region Public functions
        /// <summary>
        /// 获取所有挂号费维护信息
        /// </summary>
        /// <returns></returns>
        public override List<M7_RegistryFee> ReadAll()
        {
            string sql = @"SELECT 
                            r.FeeId,
                            r.DeptId,
                            r.OutpatientType,
                            r.RegistryType,
                            r.RegistryFee,
                            r.DiagnosticFee,
                            r.Remarks,
                            r.IsValid,
                            d.DeptId,
                            d.DeptName
                            FROM M7_RegistryFee r, M7_Department d
                                WHERE 1 = 1
                                AND r.DeptId = d.DeptId";

            using (DBHelper helper = new DBHelper())
            {
                List<M7_RegistryFee> registryFeeList = new List<M7_RegistryFee>();

                SqlDataReader reader = helper.ExecuteQuery(sql);
                while (reader.Read())
                {
                    var registryFee = new M7_RegistryFee();
                    DBUtil.ReadData(reader, registryFee);

                    var dept = new M7_Department();
                    DBUtil.ReadData(reader, dept);

                    registryFee.Dept = dept;

                    registryFeeList.Add(registryFee);
                }

                return registryFeeList;
            }
        }

        public override object Create(M7_RegistryFee registryFee)
        {
            string sql = @"
                INSERT INTO M7_RegistryFee
                        (DeptId
                        ,OutpatientType
                        ,RegistryType
                        ,DiagnosticFee
                        ,RegistryFee
                        ,Remarks
                        ,IsValid)
                    VALUES
                        (@DeptId
                        ,@OutpatientType
                        ,@RegistryType
                        ,@DiagnosticFee
                        ,@RegistryFee
                        ,@Remarks
                        ,@IsValid)
                SELECT @@IDENTITY";

            using (DBHelper helper = new DBHelper())
            {
                return helper.ExecuteScalar(sql,
                    DBUtil.CreateSqlParameter(registryFee.DeptId, "DeptId"),
                    DBUtil.CreateSqlParameter(registryFee.OutpatientType, "OutpatientType"),
                    DBUtil.CreateSqlParameter(registryFee.RegistryType, "RegistryType"),
                    DBUtil.CreateSqlParameter(registryFee.DiagnosticFee, "DiagnosticFee"),
                    DBUtil.CreateSqlParameter(registryFee.RegistryFee, "RegistryFee"),
                    DBUtil.CreateSqlParameter(registryFee.Remarks, "Remarks"),
                    DBUtil.CreateSqlParameter(registryFee.IsValid, "IsValid"));
            }
        }
        #endregion

        #region  Structrue
        public RegistryFeeDAO()
        {
            m_tableName = C_M7_TableName.REGISTRY_FEE;
            m_primaryKeyName = C_ColumnName.FEE_ID;
        }
        #endregion
    }
}
